import axios from '@/libs/api.request'

const imageConversion = require("image-conversion");

export const upBase64 = (base64) => {
    return axios.request({
        url: 'https://txy.juyouhx.com/Api/Api/upBase64ToOss',
        data: {base64: base64},
        method: 'post',
        php: true
    })
}

// 获取全国省市信息，传参为省列表，传省级code查询对应市级
export const getCityList = (data) => {
    return axios.request({
        url: '/api/as/sc/city/arealist',
        data: data,
        method: 'post'
    })
}

// 上传图片到民政生产服务器
export const uploadPic = (data) => {
    return axios.request({
        // url: 'http://10.40.20.11:5000/api/uc/csc/auditOrderService/uploadPic',
        url: '/api/uc/mzsc/uploadService/uploadPic',
        data: data,
        method: 'post'
    })
}

export const imgComparison = (img1, img2) => {
    return axios.request({
        url: '/api/uc/csc/faceCompareService/createFaceCompare',
        data: {type: 2, value1: img1, value2: img2},
        method: 'post'
    })
}

export const formBuild = () => {
    return axios.request({
        url: '/api/cln/csc/autoItemForm/testform',
        method: 'get'
    })
}
export const createUpLoadFiles = (url, data) => {
    return axios.request({
        url: url,
        data: data,
        method: 'post'
    })
}
export const getSign = (data) => {
    return axios.request({
        //url: '/api/ac/subsistence/initCacheService/getSign',
        url: '/api/ac/hdplugin/ossService/getSign',
        data: data,
        method: 'post'
    })
}
export const updateUserGPY = (data) => {
    return axios.request({
        url: '/api/ac/sc/systemUserService/updateUserGPY',
        data: data,
        method: 'post'
    })
}
// 一级残疾人身份验证接口
export const disabilityInfoVerify = (data) => {
    return axios.request({
        url: '/api/uc/csc/auditOrder3rdService/disabilityInfoVerify',
        data: data,
        method: 'post'
    })
}
// 重复申请验证接口
export const repetitionApply = (data) => {
    return axios.request({
        url: '/api/uc/csc/auditOrder3rdService/repetitionApply',
        data: data,
        method: 'post'
    })
}

// 获取用户基本信息
export const getUserInfoByLoginName = (data) => {
    return axios.request({
        url: '/api/ac/sc/systemUserService/getUserInfoByLoginName',
        data: data,
        method: 'post'
    })
}

// 初始化账号基本信息
export const updateResetAccount = (data) => {
    return axios.request({
        url: '/api/ac/sc/systemUserService/updateResetAccount',
        data: data,
        method: 'post'
    })
}
// 字典表接口
export const getDictList = (data) => {
    return axios.request({
        url: '/api/as/sc/dict/getDictList',
        method: 'post',
        data: data
    })
}

// 压缩图片
export function compressImg(file) {
    var fileSize = file.size / 1024 / 1024;
    return new Promise((resolve, reject) => {
            let reader = new FileReader();
            let fileResult = "";
            let size = 1;
            console.log(fileSize)
            if (fileSize > 1 && fileSize < 2) {
                size = 0.5;
            } else if (fileSize > 2) {
                size = 0.2;
            }
            imageConversion.compress(file, size).then(res => {
                file = new File([res], file.name, {type: res.type, lastModified: Date.now()});
                reader.readAsDataURL(file);
                //开始转
                reader.onload = function () {
                    fileResult = reader.result;
                };
                //转 失败
                reader.onerror = function (error) {
                    reject(error);
                };
                //转 结束  咱就 resolve 出去
                reader.onloadend = function () {
                    resolve(fileResult);
                };
            })
        }
    )
}
